{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 10000\n"
     ]
    }
   ],
   "source": [
    "print(f\"{0}\",bin(16).replace('0b',''))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'list'>\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "sequence item 0: expected str instance, int found",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[15], line 3\u001b[0m\n\u001b[1;32m      1\u001b[0m ls\u001b[38;5;241m=\u001b[39m[\u001b[38;5;241m0b1\u001b[39m,\u001b[38;5;241m0b0\u001b[39m,\u001b[38;5;241m0b1\u001b[39m,\u001b[38;5;241m0b0\u001b[39m]\n\u001b[1;32m      2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mtype\u001b[39m(ls))\n\u001b[0;32m----> 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mbin\u001b[39m(\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mjoin\u001b[49m\u001b[43m(\u001b[49m\u001b[43mls\u001b[49m\u001b[43m)\u001b[49m))\n",
      "\u001b[0;31mTypeError\u001b[0m: sequence item 0: expected str instance, int found"
     ]
    }
   ],
   "source": [
    "ls=[0b1,0b0,0b1,0b0]\n",
    "print(type(ls))\n",
    "print(bin(''.join(ls)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'R0': 0, 'R1': 1, 'R2': 2, 'R3': 3, 'R4': 4, 'R5': 5, 'R6': 6, 'R7': 7, 'R8': 8, 'R9': 9, 'R10': 10, 'R11': 11, 'R12': 12, 'R13': 13, 'R14': 14, 'R15': 15}\n"
     ]
    }
   ],
   "source": [
    "dics = {}\n",
    "for i in range(16):\n",
    "    dics[f'R{i}'] = i\n",
    "\n",
    "print(dics)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "123\n",
      "23\n"
     ]
    }
   ],
   "source": [
    "s = \"  123 //好的\"\n",
    "comment_index = s.find('//')\n",
    "if comment_index > -1:\n",
    "    s = s[0:comment_index]\n",
    "    \n",
    "s = s.replace(' ', '')\n",
    "s = s.replace('\\t', '')\n",
    "print('1' in s)\n",
    "print(s)\n",
    "two_index = s.find('2')\n",
    "print(s[two_index:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0000000000000011\n"
     ]
    }
   ],
   "source": [
    "#format(3, 'b')\n",
    "val = 3\n",
    "\n",
    "print(f\"{val:016b}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = \"@123\"\n",
    "s.startswith('@')\n",
    "s.endswith(')')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123\n"
     ]
    }
   ],
   "source": [
    "s = '   123 '\n",
    "print(s.strip())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'dict'>\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dics = {\n",
    "            'SP':0, 'LCL':1, 'ARG':2, 'THIS':3, 'THAT':4,\n",
    "            'SCREEN':16384, 'KBD':24576\n",
    "            }\n",
    "symbol = 'SP'\n",
    "print(type(dics))\n",
    "symbol in dics.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0,0\n",
      "1,1\n"
     ]
    }
   ],
   "source": [
    "class Pos2Pos:\n",
    "    def __init__(self, asm_index, hack_index) -> None:\n",
    "        self.asm_index = asm_index\n",
    "        self.hack_index = hack_index\n",
    "        pass\n",
    "ls = [Pos2Pos(0, 0),Pos2Pos(1, 1)]\n",
    "for item in ls:\n",
    "    print(f\"{item.asm_index},{item.hack_index}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10%\n"
     ]
    }
   ],
   "source": [
    "n = 10.14\n",
    "print(f\"{n:.0f}%\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'ValueError'>:出错了\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "try:\n",
    "    raise ValueError(\"出错了\")\n",
    "    pass\n",
    "except:\n",
    "    exctype, value = sys.exc_info()[:2]\n",
    "    print(f\"{exctype}:{value}\")\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n",
      "b\n",
      "c\n"
     ]
    }
   ],
   "source": [
    "s = 'abc'\n",
    "for c in s:\n",
    "    print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "ename": "RuntimeError",
     "evalue": "Please destroy the QApplication singleton before creating a new QApplication instance.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mRuntimeError\u001b[0m                              Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[5], line 19\u001b[0m\n\u001b[1;32m     16\u001b[0m             selected_file \u001b[38;5;241m=\u001b[39m file_dialog\u001b[38;5;241m.\u001b[39mselectedFiles()[\u001b[38;5;241m0\u001b[39m]\n\u001b[1;32m     17\u001b[0m             \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSelected file: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mselected_file\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 19\u001b[0m app \u001b[38;5;241m=\u001b[39m \u001b[43mQApplication\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m     20\u001b[0m window \u001b[38;5;241m=\u001b[39m MainWindow()\n\u001b[1;32m     21\u001b[0m window\u001b[38;5;241m.\u001b[39mshow()\n",
      "\u001b[0;31mRuntimeError\u001b[0m: Please destroy the QApplication singleton before creating a new QApplication instance."
     ]
    }
   ],
   "source": [
    "from PySide6.QtWidgets import QApplication, QFileDialog, QMainWindow, QPushButton\n",
    " \n",
    "class MainWindow(QMainWindow):\n",
    "    def __init__(self):\n",
    "        super().__init__()\n",
    "        button = QPushButton(\"Save File\")\n",
    "        button.clicked.connect(self.open_save_dialog)\n",
    "        self.setCentralWidget(button)\n",
    " \n",
    "    def open_save_dialog(self):\n",
    "        file_dialog = QFileDialog()\n",
    "        file_dialog.setDefaultSuffix(\".txt\")  # 设置默认文件名后缀为.txt\n",
    "        file_dialog.setAcceptMode(QFileDialog.AcceptSave)  # 设置对话框为保存模式\n",
    "        file_dialog.setWindowTitle(\"Save File\")\n",
    "        if file_dialog.exec() == QFileDialog.Accepted:\n",
    "            selected_file = file_dialog.selectedFiles()[0]\n",
    "            print(f\"Selected file: {selected_file}\")\n",
    " \n",
    "app = QApplication([])\n",
    "window = MainWindow()\n",
    "window.show()\n",
    "app.exec()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
